﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AzureProvider.ssdsClient;
using System.Collections.Specialized;

namespace AzureProvider.SoupMethods
{
    public abstract class PostRelatedMethods : BaseMethods
    {
        public void DeletePostRelated(string PostId, out string errMessage)
        {
            string qry = null;
            if (PostId != null)
                qry = string.Format(" from e in entities where e.Kind == \"{0}\" && e[\"PostId\"] == \"{1}\"  select e", kind, PostId);
            foreach (Entity ent in GetEntities(qry, out errMessage))
            {
                Delete(ent.Id);
            }
        }
    

        public void Insert(string PostId, object[] related, out string errMessage)
        {
            errMessage = null;

            foreach (object obj in related)
            {
                Insert(obj,out errMessage);
            }
        }

        public void Update(string PostId, object[] related, out string errMessage)
        {
            errMessage = null;

            DeletePostRelated(PostId, out  errMessage);
            Insert(PostId,  related, out  errMessage);
        }



    }
}
